﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using Pahan.McuFusion.Common;
using Pahan.McuFusion.Files;
using Pahan.McuFusion.UI.Events;
using Pahan.McuFusion.UI.RecentFiles;
using Pahan.McuFusion.UI.Workspaces;

namespace Pahan.McuFusion.UI.Interfaces
{
    public interface IMainView
    {
        /// <summary>
        /// Raised when the user performs some action to create a new workspace.
        /// </summary>
        event EventHandler NewWorkspaceRequested;

        /// <summary>
        /// Raised when the user wants to save the workspace to file.
        /// </summary>
        event EventHandler SaveWorkspaceRequested;

        /// <summary>
        /// Raised when the user wants to save the workspace to file.
        /// </summary>
        event EventHandler SaveWorkspaceAsRequested;

        /// <summary>
        /// Raised when the user wants to open a workspace from file.
        /// </summary>
        event OpenWorkspaceEventHandler OpenWorkspaceRequested;

        /// <summary>
        /// Raised when the user wants to read the content of the memory.
        /// </summary>
        event MemoryOperationEventHandler ReadMemoryRequested;

        /// <summary>
        /// Raised when the user wants to open the file with the firmware.
        /// </summary>
        event MemoryOperationEventHandler OpenFileRequested;

        /// <summary>
        /// Raised when the user wants to save the file with the firmware.
        /// </summary>
        event MemoryOperationEventHandler SaveFileRequested;

        /// <summary>
        /// Raised when the user wants to write the content of the file
        /// to the memory of the device.
        /// </summary>
        event MemoryOperationEventHandler WriteMemoryRequested;

        /// <summary>
        /// Raised when the user wants to erase the memory.
        /// </summary>
        event MemoryOperationEventHandler EraseMemoryRequested;

        /// <summary>
        /// Raised when the user wants to run the script.
        /// </summary>
        event EventHandler RunScriptRequested;

        /// <summary>
        /// Raised when the view is loaded.
        /// </summary>
        event EventHandler Loaded;

        /// <summary>
        /// Raised when the view is closing.
        /// </summary>
        event CancelEventHandler Closing;

        /// <summary>
        /// Shows the workspace.
        /// </summary>
        void ShowWorkspace(Workspace workspace);

        /// <summary>
        /// Asks the user to select the workspace file to open.
        /// </summary>
        /// <returns>The <see cref="FileInfo"/> object for the file selected by the user 
        /// or null if the user has cancelled the operation.</returns>
        FileInfo GetOpenWorkspaceName();

        /// <summary>
        /// Asks the user to select the file name to save the workspace.
        /// </summary>
        /// <returns>The <see cref="FileInfo"/> object for the file selected by the user 
        /// or null if the user has cancelled the operation.</returns>
        FileInfo GetSaveWorkspaceName();

        /// <summary>
        /// Shows the content of memory.
        /// </summary>
        void ShowMemory(IList<byte> bytes, MemoryClassInfo memoryClass);
        
        /// <summary>
        /// Gets the content of memory.
        /// </summary>
        IList<byte> GetMemory(MemoryClassInfo memoryClass);

        /// <summary>
        /// Asks the user to select the file to open.
        /// </summary>
        /// <returns>The <see cref="FileInfo"/> object for the file selected by the user 
        /// or null if the user has cancelled the operation.</returns>
        FileInfo GetOpenFileName(IEnumerable<FileTypeInfo> fileTypes);

        /// <summary>
        /// Asks the user to select the file to open.
        /// </summary>
        /// <param name="fileTypes">The dictionary containing the file type display names as keys
        /// and lists of possible extensions as values.</param>
        FileInfo GetOpenFileName(IEnumerable<KeyValuePair<string, IEnumerable<string>>> fileTypes);

        /// <summary>
        /// Asks the user to select the file name to save.
        /// </summary>
        /// <returns>The <see cref="FileInfo"/> object for the file selected by the user 
        /// or null if the user has cancelled the operation.</returns>
        FileInfo GetSaveFileName(IEnumerable<FileTypeInfo> fileTypes);

        /// <summary>
        /// Refreshes the list of recent files.
        /// </summary>
        void RefreshRecentFilesList(IEnumerable<RecentFile> files);

        /// <summary>
        /// Asks the you whether he wants to save changes and close the workspace.
        /// </summary>
        /// <returns>
        /// True if the user wants to save changes; 
        /// false if he wants to discard changes;
        /// null if he does not want to close the workspace.
        /// </returns>
        bool? ConfirmCloseWorkspace();

        /// <summary>
        /// Shows the error message.
        /// </summary>
        void ShowError(String message);

        /// <summary>
        /// Closes the view and halts the application.
        /// </summary>
        void Close();
    }
}
